package com.Calculator.view.Button.impl;


import com.Calculator.models.impl.CommandsName;
import com.Calculator.models.impl.Theme;
import com.Calculator.view.Button.iMyJButton;
import javax.swing.*;
import java.awt.*;

public class CommandsButton implements iMyJButton{
    private JButton[] commands;

    public CommandsButton(Theme theme) {
        //获取command名字对象
        CommandsName commandsName = new CommandsName();
        //command按钮对象数组
        this.commands = new JButton[commandsName.getLength()];

        //初始化commands按钮
        for(int i = 0; i < commands.length; i++) {
            //设置文本
            this.commands[i] = new JButton(commandsName.getName()[i]);
            this.commands[i].setPreferredSize(new Dimension(60,60));
            this.commands[i].setFont(theme.getFont());
            this.commands[i].setBackground(theme.getButtonColor());
            this.commands[i].setBorder(BorderFactory.createRaisedBevelBorder());
            this.commands[i].setForeground(Color.RED); // 设置按键颜色为红色
        }
    }

    public JPanel setPanel() {
        JPanel commandsPanel = new JPanel(new GridLayout(1,4,3,3));
        commandsPanel.setBorder(BorderFactory.createEmptyBorder(30, 30, 0, 30));

        for (JButton command : commands) {
            commandsPanel.add(command);
        }
        return commandsPanel;
    }


    @Override
    public JButton[] getButton() {
        return commands;
    }

    @Override
    public void setButton(JButton[] button) {
        this.commands = button;
    }
}
